/*
 * Powered By [信安]
 * Since 2013 - 2013
 */

package com.xinan.system.curd;

import com.jfinal.ext.plugin.tablebind.TableBind;
import com.jfinal.kit.StringKit;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

/**
 * @author EricLee
 * @version 1.0
 * @since 1.0
 */

@TableBind(tableName = "auth_user")
public class newPassword extends Model<newPassword>{
    public static final newPassword dao = new newPassword();

    //columns START
    public int getId() {
        return get("id");
    }
    public String getUsername() {
        return get("username");
    }
    public String getCnname() {
        return get("cnname");
    }
    public String getPassword() {
        return get("password");
    }
    public String getEmail() {
        return get("email");
    }
    public String getPhone() {
        return get("phone");
    }
    public String getMobile() {
        return get("mobile");
    }
    public String getStatus() {
        return get("status");
    }
    public String getRmk() {
        return get("rmk");
    }
    public String getOptname() {
        return get("optname");
    }
    public Timestamp getOptdate() {
        return get("optdate");
    }
    //columns END

    public List<newPassword> findAll() {
        return find("select * from auth_user");
    }

    public newPassword findByUserName(String userName){
        return findFirst("select * from auth_user where username=?",userName);
    }

    public Page<newPassword> page(int pageNumber, int pageSize, String where) {
        String sqlExp = "from auth_user";
        if(StringKit.notBlank(where)){
            sqlExp += " where " + where;
        }
        return paginate(pageNumber, pageSize, "select *", sqlExp);
    }

    public List<newPassword> findByRoleName(String roleName)
    {
        List<newPassword> result = new ArrayList<newPassword>();
        AuthRole ar = AuthRole.dao.findByRoleName(roleName);
        if(null!=ar)
        {
            int id = ar.getId();
            result = find("select a.* from auth_user a left join auth_user_role b on a.id = b.userid where b.roleid=?",id);
        }
        return result;
    }
}

